<!-- * WanlShop - App全局模板配置
 * @author 深圳前海万联科技有限公司 <wanlshop@i36k.com> 
 * @link http://www.wanlshop.com
 * 
 * @本程序受法律保护，著作权©软著登记号2020SR0255711 < 非FastAdmin购买授权，未经版权所有权人书面许可，不能用于商业用途！>
 * 
 * @获取许可
 * 后台下载：https://www.fastadmin.net/store/wanlshop.html
 * 帮助文档：https://doc.fastadmin.net/wanlshop
 * 
 * @stress 本程序仅用作FastAdmin付费插件（WanlShop B2B2C商城）API使用，非FastAdmin购买授权，未经版权所有权人书面许可，不能自行用于商业用途
 * @creationtime  2019年9月10日12:52:20
 * @lasttime 2020年6月9日09:26:07
 * @version 1.0.0
 -->

 
<script>
	import Vue from 'vue';
	import jvue from '@/libs/jdk/jvue';
	//import auth from '@/libs/wechat';
	export default {
		globalData: {
			appName: '',
			appNameLite: '享乐汇',
			// baseUrl: 'http://aikm.cc',
			version: '1.*.*',
			order_ttl : 1800000, //订单过期时间，30分钟
			haggle_ttl : 172800000 //砍价过期时间，24小时
		},
		onLaunch(e) {
			//console.log(e,'8999999999全局参数')
			if(e.query?.inviter_code){
				uni.setStorageSync('inviter_code',e.query.inviter_code);
				//console.log("邀请码",e.query.inviter_code);
			}
			// 检测客户端更新
			this.$store.dispatch('update/update');
			// 仅首次打开一次性加载数据
			this.$store.dispatch('common/init');
			// 同步购物车 本地 & 网络
			this.$store.dispatch('cart/get');
			// 同步 动态数据
			this.$store.dispatch('statistics/get');
		},
		onLoad(options){
			//console.log(options);
		},
		onShow(options) {
			
			//console.log(options);
			// 启动或重启即时通讯
			// this.$store.dispatch('chat/connectSocket');
		},
		onHide() {
			// 断开即时通讯
			// this.$store.dispatch('chat/close');
		},
		methods : {
			showModal(title,content,func){
				var that = this;
				var fixcontent = content.replace(/<br>/g,"\n");
				uni.showModal({
					title: title,
					content: fixcontent,
					success: function (resp) {
						console.log("showModel",resp);
						if (resp.confirm) {
							//if(func!=undefined) func();
							//that.toUrl(url,mode);
							func();
						}
					}
				})
			},
			tips(msg){
				this.$util.Tips({
					title: msg
				});
			},
			showMsg(title = '', icon = 'none',duration = 2000){
				this.appShowToast(title, icon, false, duration);
			},
			appShowToast(title = '', icon = 'none', mask = true, duration = 2000, position = 'center') {
				uni.hideLoading();
				return uni.showToast({
					title: title,
					icon: icon,
					mask: mask,
					duration: duration,
					position: position
				});
			},
			isEmpty(val) {
				if (val == '' || val == null || val == 0 || val == undefined) {
					return true;
				}
				return false;
			},
			appShowLoading(title = '', mask = true) {
				uni.showLoading({
					title: title,
					mask: mask
				});
			},
			appStringLength(val) {
				val = val == '' || val == null || val == 0 || val == undefined ? 0 : val;
				return val.length;
			},
			//APP 微信支付
			appWechatPayment(jsConfig) {
				return new Promise((resolve, reject) => {
					uni.requestPayment({
						orderInfo: jsConfig,
						provider: 'wxpay',
						success: function(res) {
							resolve(res);
						},
						fail: function(e) {
							reject(e);
						},
						complete: function(e) {
							reject(e);
						}
					});
				});
			},
			toAuth(){
				//to
				$jvue.toUrl("/pages/user/auth/auth");
			},
			toLogin(){
				$jvue.toUrl("/pages/user/auth/name");
			},
			wxAuth(){ //微信公众号授权
				if(!auth){
					alert("只能在微信公众号下执行!");return ;
				}
				if(!auth.isWeixin()){
					alert("只能在微信公众号下执行!");return ;				
				}
				auth.oAuth();
				//auth.isWeixin() && auth.oAuth();
			},
			wxAuthBind(){
				if(!auth){
					alert("只能在微信公众号下执行!");return ;
				}
				if(!auth.isWeixin()){
					alert("只能在微信公众号下执行!");return ;				
				}
				auth.oAuthBind();
			},
			getWxUser(){
				console.log('-------获取openid(unionid)-----');
				uni.getUserInfo({
					provider: 'weixin',
					success: function(infoRes) {
						console.log('-------获取微信用户所有-----');
						var infoResData = JSON.stringify(infoRes.userInfo);
						var data = {};
						data.openid = infoRes.userInfo.openId;
						data.unionid = infoRes.userInfo.unionId;
						data.nickname = infoRes.userInfo.nickName;
						data.headimgurl = infoRes.userInfo.avatarUrl;
					},
				});
				
			},
			isDebug(){
				return location.host.indexOf('localhost')!=-1;
			},
			toUrl(url,mode){
				return jvue.toUrl(url,mode);
			},
			toAuthUrl(url) {				
				if (!this.isLogin()) {
					//return this.checkLogin();
					return ;
				}
				this.toUrl(url);
			},
			copyClip(value) {
				return jvue.copyClip(value);							
			},
			back(){
				uni.navigateBack({delta: 1});				
			},	
			toIndex(){
				uni.switchTab({	url: "/"});
			},
			toMain(){
				app.toUrl("/",'tab');			
			},
			toMy(){
				uni.switchTab({	url: "/pages/user"});
			},
			showReferCode(){
				 uni.request({
					url: '/wanlshop/user/refresh',
					method: 'POST',
					success: res => {
						// console.log(res.data.userinfo, '89999999999999999999999999999999999')
						if (res.data.userinfo.inviter_id) {
							//this.$wanlshop.to('/pages/user/money/withdraw')
						} else {
							uni.showModal({
								title: '请填写推荐人给您邀请码以便获得奖励',
								content: '',
								editable: true, //是否显示输入框
								placeholderText: '请输入上级邀请码', //输入框提示内容
								confirmText: '确认',
								cancelText: '取消',
								success:   (res) => {
									if (res.confirm) {
										console.log('输入的内容：', res.content);
										if(!res.content) return this.$wanlshop.msg('请输入上级手机号')
										 uni.request({
											url:"/wanlshop/user/inviter_id",
											method:"POST",
											data:{
												mobile:res.content
											},
											success: (res) => {
												this.$wanlshop.to('/pages/user')
											}
										})
									}
								}
							})
						}
					}
				});
			},
			
		}
	};
</script>

<style>
	/* #ifndef APP-NVUE */
	@import 'static/style/colorui.css';
	@import 'static/style/wanlshop.css';
	@import 'static/style/iconfont.css';
	/* #endif */
	
	.middle-button{
			
	}
</style>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-ui/index.scss";
</style>
